package cn.xfdzx.android.apps.shop.presenter;

import java.util.Map;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.AddAddressBeen;
import cn.xfdzx.android.apps.shop.bean.PeiSongBeen;
import cn.xfdzx.android.apps.shop.bean.ReturnReasonBean;
import cn.xfdzx.android.apps.shop.contract.AddAddressContract;
import cn.xfdzx.android.apps.shop.contract.PeisongyuanContract;
import cn.xfdzx.android.apps.shop.model.AddAddressModel;
import cn.xfdzx.android.apps.shop.model.PeiSongModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author azheng
 * @date 2018/6/4.
 * Description：
 */
public class PeiSongPresenter extends BasePresenter<PeisongyuanContract.View> implements PeisongyuanContract.Presenter {

    private PeisongyuanContract.Model model;

    public PeiSongPresenter() {
        model = new PeiSongModel();
    }



    @Override
    public void peiSong(String order_id) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.peisongyuan(order_id )
                .compose(RxScheduler.<PeiSongBeen>Flo_io_main())
                .as(mView.<PeiSongBeen>bindAutoDispose())
                .subscribe(new Consumer<PeiSongBeen>() {
                    @Override
                    public void accept(PeiSongBeen bean) throws Exception {
                        mView.onPeiSongSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void getRefundRreason() {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getRefundRreason()
                .compose(RxScheduler.<ReturnReasonBean>Flo_io_main())
                .as(mView.<ReturnReasonBean>bindAutoDispose())
                .subscribe(new Consumer<ReturnReasonBean>() {
                    @Override
                    public void accept(ReturnReasonBean bean) throws Exception {
                        mView.getRefundRreasonSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void getAfterServiceRequest(Map<String, Object> param) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getAfterServiceRequest(param)
                .compose(RxScheduler.<ReturnReasonBean>Flo_io_main())
                .as(mView.<ReturnReasonBean>bindAutoDispose())
                .subscribe(new Consumer<ReturnReasonBean>() {
                    @Override
                    public void accept(ReturnReasonBean bean) throws Exception {
                        mView.getAfterServiceRequestSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

}
